package main

import (
	"fmt"
	"github.com/urfave/cli/v3"
	"sort"
)

func main() {
	var tag string
	app := &cli.App{
		Name:        "Deploy",
		Usage:       "项目打包工具",
		Description: "项目打包工具,将打好的包上传至存储中心上面，运维人员作发布",
		Commands: []*cli.Command{
			{
				Name:    "deploy",
				Aliases: []string{"p"},
				Usage:   "deploy project",
				Subcommands: []*cli.Command{
					{
						Name:    "clone",
						Aliases: []string{"c"},
						Usage:   "init the project",
						Action: func(c *cli.Context) error {
							fmt.Println("拉取代码")
							return nil
						},
					},
					{
						Name:    "build",
						Aliases: []string{"b"},
						Usage:   "build the project as tar to ftp",
						Action: func(c *cli.Context) error {
							fmt.Println("编译")
							return nil
						},
						Flags: []cli.Flag{
							&cli.StringFlag{
								Name:     "domain",
								Aliases:  []string{"d"},
								Value:    "release-domain",
								Usage:    "指定工程的域名",
								Required: false,
							},
							&cli.StringFlag{
								Name:        "tag",
								Aliases:     []string{"t"},
								Value:       "release-tag",
								Usage:       "打包项目的git的tag发布版本号",
								Destination: &tag,
								Required:    false,
							},
						},
					},
					{
						Name:    "view",
						Aliases: []string{"ls"},
						Usage:   "list the project",
						Action: func(c *cli.Context) error {

							return nil
						},
					},
				},
				Flags: []cli.Flag{
					&cli.StringFlag{
						Name:     "domain",
						Aliases:  []string{"d"},
						Value:    "release-domain",
						Usage:    "指定工程的域名",
						Required: false,
					},
				},
				Action: func(c *cli.Context) error {
					fmt.Println("请指定具体操作: init、ls、build或用 -h 查看命令")
					return nil
				},
			},
		},
	}

	sort.Sort(cli.FlagsByName(app.Flags))
	sort.Sort(cli.CommandsByName(app.Commands))
}
